/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.groupbuy.multishop.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.groupbuy.common.model.GroupSku;
import com.yami.shop.groupbuy.common.service.GroupSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author LGH
 * @date 2019-08-27 17:55:57
 */
@RestController
@AllArgsConstructor
@RequestMapping("/group/sku")
@Api(tags = "商家端团购商品规格接口")
public class GroupSkuController {

    private final GroupSkuService groupSkuService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查找团购商品规格列表")
    public ServerResponseEntity<IPage<GroupSku>> getGroupSkuPage(PageParam<GroupSku> page, GroupSku groupSku) {
        return ServerResponseEntity.success(groupSkuService.page(page, new LambdaQueryWrapper<GroupSku>()));
    }

    @GetMapping("/info/{groupSkuId}")
    @ApiOperation(value = "通过id查询团购商品规格活动")
    @ApiImplicitParam(name = "groupSkuId", value = "团购商品规格id", required = true, dataType = "Long")
    public ServerResponseEntity<GroupSku> getById(@PathVariable("groupSkuId") Long groupSkuId) {
        return ServerResponseEntity.success(groupSkuService.getById(groupSkuId));
    }

    @PostMapping
    @ApiOperation(value = "新增拼团活动商品规格")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid GroupSku groupSku) {
        return ServerResponseEntity.success(groupSkuService.save(groupSku));
    }

    @PutMapping
    @ApiOperation(value = "修改拼团活动商品规格")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid GroupSku groupSku) {
        return ServerResponseEntity.success(groupSkuService.updateById(groupSku));
    }

    @DeleteMapping("/{groupSkuId}")
    @ApiOperation(value = "通过id删除拼团活动商品规格")
    @ApiImplicitParam(name = "groupSkuId", value = "团购商品规格id", required = true, dataType = "Long")
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long groupSkuId) {
        return ServerResponseEntity.success(groupSkuService.removeById(groupSkuId));
    }
}
